var header = $("meta[name='_csrf_header']").attr("content");
var token =$("meta[name='_csrf']").attr("content");


var table;
layui.use('table', function(){
    table = layui.table;
    // table.render({
    //     elem: '#address'
    //     ,url:"/getOrderList"
    //     ,cellMinWidth: 80
    //     ,cols: [[
    //         {type:'numbers'}
    //         ,{type: 'checkbox'}
    //         ,{field:'orderNo', title:'订单编号'}
    //         ,{field:'pOrderTime', title:'下单时间',templet :function (row){return createTime(row.pOrderTime);}}
    //         ,{field:'orderMoney', title:'订单金额'}
    //         ,{field:'orderStatus', title: '订单状态'}
    //         ,{field:'opratorCost', title: '运营成本'}
    //         ,{field:'freight', title: '运费'}
    //         ,{field:'avaCoupon', title: '可用购物券'}
    //         ,{field:'avaCashcoupon', title: '可用代金券'}
    //         ,{field:'logisticalType', title: '物流类型'}
    //         ,{field:'orderNo', title:'操作', minWidth:180, templet: '#barDemo', unresize: true}
    //
    //     ]]
    //     ,page: true
    //     ,limlt:10
    //     //,limits: [10,30,50,100]
    //     ,id: 'orlist'
    // });

});




function createTime(v){
    return new Date(parseInt(v)).toLocaleString()
}
/**重写toLocaleString方法*/
Date.prototype.toLocaleString = function() {
    var y = this.getFullYear();
    var m = this.getMonth()+1;
    m = m<10?'0'+m:m;
    var d = this.getDate();
    d = d<10?("0"+d):d;
    var h = this.getHours();
    h = h<10?("0"+h):h;
    var M = this.getMinutes();
    M = M<10?("0"+M):M;
    var S=this.getSeconds();
    S=S<10?("0"+S):S;
    return y+"-"+m+"-"+d+" "+h+":"+M+":"+S;}

function openDetails() {
    layer.open({
        type: 2
        , title: '添加会员等级'
        , content: '/getOrderDetails'
        , area: ['420px', '420px']
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            debugger;
            var body = layer.getChildFrame('body', index); //得到iframe页的body内容
            var loginname = body.find("#loginname").val();
            alert(loginname);

            //table.reload('LAY-user-front-submit'); //数据刷新
            layer.close(index); //关闭弹层
        }
    });
}


function editLogAddress(obj) {
    layer.open({
        type: 2
        , title: '修改收货地址'
        , content: '/editLogAddress?id='+$(obj).attr('data')
        , area: ['850px', '520px']
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            var body = layer.getChildFrame('body', index); //得到iframe页的body内容
            var id = $.trim(body.find("#sure").attr('data'));
            var name=$.trim(body.find("#name").val());
            var phone=$.trim(body.find("#phone").val());
            var logtype=$.trim(body.find("#logtype").val());
            var orderNo=$.trim($("#spanOrderNo").html());
            var address=$.trim(body.find("#address").attr('data'));
            var userId=$.trim(body.find("#address").attr('userId'));
            if(address.split(',').length!=3){
                alert("请选择完地址(省-市-区)!");return;
            }
            var detailAddress=$.trim(body.find("#detailAddress").val());
            //alert(id+"--"+name+"--"+phone+"--"+address+"--"+detailAddress+"---"+logtype);return;
            $.ajax({
                url:"/editLogAddressData?id="+id+"&name="+name+"&phone="+phone+"&address="+address+"&detailAddress="+detailAddress+"&logtype="+logtype+"&orderNo="+orderNo+"&userId="+userId,
                success:function (result) {
                    if(result.data>0){
                        alert("成功！");
                    }
                    else {
                        alert("失败！");
                    }
                },
                beforeSend : function(xhr) {
                    xhr.setRequestHeader(header, token);
                }
            });
            //数据刷新
            //var demoReload = $('#demoReload');
            //执行重载
            // table.reload('testReload', {
            // });
            layer.close(index); //关闭弹层
        }
    });
}


function editchangeproduct(obj) {
    var adids=$.trim($("#address").attr('adid'));
    var id = $.trim($(obj).attr('sure'));
    var name=$.trim($("#name").val());
    var phone=$.trim($("#phone").val());
    var logtype=$.trim($("#logtype").val());
    var address=$.trim($("#address").attr('data'));
    var length1=address.split(',').length;
    var userId=$.trim($("#userId").val());
    // if(address.split(',').length!=3){
    //     alert("请选择完地址(省-市-区)!");return;
    // }
    if(address.split(',')[0]==0&&length1==1){
        address=adids;
    }else if(length1!=3&&length1>0) {
        alert("请选择完地址(省-市-区)!");return;
    }
    var detailAddress=$.trim($("#detailAddress").val());
    var remark=$.trim($("#remark").val());
    //alert(id+"--"+name+"--"+phone+"--"+address+"--"+detailAddress+"--"+logtype+"--"+remark);return;
    var tabInfo="";
    $("#changeProductTable tbody").find("tr").each(function(){
        var tdArr = $(this);
        var id=tdArr.find(".id").html();
        var name=tdArr.find(".name").html();
        var number=tdArr.find(".number").find('input').val();
        var price=tdArr.find(".price").html();
        tabInfo+=id+","+name+","+number+","+price+"-"
    });
    if(tabInfo!=""){
        tabInfo=tabInfo.substring(0,tabInfo.length-1);
    }
    var orderNo=$("#spanOrderNo").html();
    // alert(tabInfo);
    // return;
    // var id=$(obj).parent().parent().find(".id").html();
    // var name=$(obj).parent().parent().find(".name").html();
    // var number=$(obj).parent().parent().find(".number").find('input').val();
    // var price=$(obj).parent().parent().find(".price").html();
     //alert(tabInfo+"--"+orderNo);return;
    //alert(id+"--"+name+"--"+phone+"--"+address+"--"+detailAddress+"--"+logtype+"--"+remark+"--"+tabInfo+"--"+orderNo);return;

    $.ajax({
        url: '/changeProductCart',
        data:{
            id:id,
            name:name,
            phone:phone,
            address:address,
            detailAddress:detailAddress,
            logtype:logtype,
            orderNo:orderNo,
            userId:userId,
            tabInfo:tabInfo,
            remark:remark
        },
        type: 'post',
        dataType: 'json',
        async: false,
        success: function(data){
                if(data.data>0){
                    alert("成功!");
                }else if(data.data==-2){
                    alert("已经导单不允许修改!");
                }
                else {
                    alert("失败!");
                }
        },
        beforeSend : function(xhr) {
        xhr.setRequestHeader(header, token);
    }
    });
}




